package global

import (
	_redis "github.com/go-redis/redis"
	"shorturl/configs"
	"shorturl/utils"
)

var Redis *_redis.Client

func init() {
	config, _ := configs.ReadConfig(utils.GetRootPath() + "/config.json")

	Redis = _redis.NewClient(&_redis.Options{
		Addr:     config.Redis.Host + ":" + config.Redis.Port,
		Password: config.Redis.Password,
		DB:       config.Redis.Db, // use default DB
	})

	_, err = Redis.Ping().Result()

	if err != nil {
		panic("failed to connect redis")
	}
}
